/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import model.PacienteDAO;
import model.ProfissionalDAO;
import model.Usuario;

/**
 *
 * @author Eduarda
 */
public class TrataPrePesquisaPaciente extends Comando {

    @Override
    public void executar(HttpServletRequest request, HttpServletResponse response) throws ClassNotFoundException, SQLException, IOException, ServletException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        // Recupera o objeto de sessão que identifica quem está solicitando o serviço
        HttpSession session = request.getSession(false);
        Usuario value = (Usuario) session.getAttribute("identifica");
        if (value != null) {
            try {
                ArrayList listaPacientes = new PacienteDAO().pesquisarPacientes();

                HttpSession session2 = request.getSession(true);
                session2.setAttribute("listaPesquisarPacientes", listaPacientes);
                //Redireciona para outra página
                response.sendRedirect("pesquisarPacientes.jsp");

            } catch (ClassNotFoundException ioex) {
                throw new ServletException(ioex);
            } catch (SQLException sqlex) {
                throw new ServletException(sqlex);
            }
        }
    }
    
}
